<div class='section'>
<h1>Statistics</h1>

<?php 

	$stats = array(
		'Total amount of users' => count($view->users),
		'Total amount of users registered in the last 3 months' => $view->statistics['signed_up_recently'],
		'Total amount of users active in the last 3 months' => $view->statistics['active_recently'],
		'Total amount of messages sent in the last 3 months' => $view->statistics['messages_recently'],
		'Total amount of users interested in the newsletter' => count($view->newsletter_addresses),
		'Theoretical amount of possible couples' => $view->statistics['couples_possible'],
	);
	
	echo '<table>';
	foreach ($stats as $stat => $value) {
		echo "<tr><td>$stat</td><td>$value</td></tr>";
	}
	echo '</table>';

	echo '<p>Language overview</p>';
	echo "<ul>";
	foreach ($view->statistics['languages_summary'] as $lang_code => $data) {
		echo '<li>'. LanguageCodeInput::get_english_language_name($lang_code) . ': ' . 
					$data['known'] . ' tutors for ' . $data['unknown'] . ' pupils</li>';
	}
	echo "</ul>";
	
?>
	<div style='clear:both;'></div>
</div>

<div class='section'>
	<h1>Newsletter email addresses</h1>
	<p><strong>Always</strong> send newsletters with the addresses in the <strong>bcc</strong> field.</p>
	<div>
		<?php 
		if (! $view->newsletter_addresses) {
			echo '<p>Nobody wants to receive the neswletter :-(</p>';
		}
		else {
			echo implode(', ', $view->newsletter_addresses);
		}
		?>
	</div>
	<div style='clear:both;'></div>
</div>


<div class='section'>
	<h1>Users</h1>
	<table id='user-summary'>
		<tr><th>Name</th><th>Email</th><th>Member since</th><th>Messages</th><th></th><th></th></tr>
		<?php 
			require_once 'actions/manage_block.cls.php';
			
			$administrate = r(new ManageBlockAction())->get_direct_link();
			$remove_link = r(new RemoveUserAction())->get_direct_link();
			
			foreach ($view->users as $user) {
				
				$administrate->set_value(ManageBlockAction::INPUT_BLOCKED_USER_ID, $user->user_id);
				$remove_link->set_value(RemoveUserAction::INPUT_USER_ID, $user->user_id);
				
				if ($user->blocked) {
					$message = 'Unblock';
					$administrate->set_value(ManageBlockAction::INPUT_OPERATION, ManageBlockAction::UNBLOCK);
					$remove = "<a href='{$remove_link->__toString()}'>Remove</a>";
				}
				else {
					$message = 'Block';
					$administrate->set_value(ManageBlockAction::INPUT_OPERATION, ManageBlockAction::BLOCK);
					$remove = '';
				}
				
				$signup_date = date_to_slash_date_string($user->signup_date);
				echo "<tr>
						<td>{$user->first_name} {$user->last_name}</td>
						<td>{$user->email}</td>
						<td>{$signup_date}</td>
						<td>{$view->messages_sent[$user->user_id]}</td>
						<td><a href='{$administrate->__toString()}'>$message</a></td>
						<td>$remove</td>
					</tr>
				";
			}
		?>
	</table>
</div>